package com.ctsi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctsi.common.util.Search;
import com.ctsi.core.common.enums.StatusType;
import com.ctsi.core.common.util.$;
import com.ctsi.core.database.util.PageUtil;
import com.ctsi.system.entity.Pos;
import com.ctsi.system.mapper.PosMapper;
import com.ctsi.system.service.IPosService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统职位表 服务实现类
 * </p>
 *
 * @author wang xiao xiang
 */
@Service
public class PosServiceImpl extends ServiceImpl<PosMapper, Pos> implements IPosService {

	@Override
	public IPage<Pos> listPage(Search search) {
		boolean isKeyword = $.isNotBlank(search.getKeyword());
		LambdaQueryWrapper<Pos> queryWrapper = Wrappers.<Pos>lambdaQuery()
				// 根据名称查询
				.like(isKeyword, Pos::getName, search.getKeyword())
				.or(isKeyword)
				// 根据编码查询
				.like(isKeyword, Pos::getCode, search.getKeyword())
				// 排序
				.orderByAsc(Pos::getSort);
		return this.baseMapper.selectPage(PageUtil.getPage(search), queryWrapper);
	}

	@Override
	public List<Pos> list(Pos pos) {
		return this.list(Wrappers.<Pos>lambdaQuery()
				.select(Pos::getId, Pos::getCode, Pos::getName, Pos::getCode, Pos::getRemark, Pos::getStatus)
				// 职位编码模糊查询
				.like($.isNotEmpty(pos.getCode()), Pos::getCode, pos.getCode())
				.eq(Pos::getStatus, StatusType.ENABLE.getCode())
				.orderByAsc(Pos::getSort));
	}
}
